package com.nbsystem.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbsystem.entity.ElcInfotype;
import com.nbsystem.service.ElcInfotypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (ElcInfotype)表控制层
 *
 * @author makejava
 * @since 2021-06-01 15:04:43
 */
@RestController
@RequestMapping("/elcInfotype")
public class ElcInfotypeController {
    /**
     * 服务对象
     */
    @Resource
    private ElcInfotypeService elcInfotypeService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ElcInfotype selectOne(Integer id) {
        return this.elcInfotypeService.queryById(id);
    }


    @RequestMapping("list")
    public PageInfo<ElcInfotype> queryAll(ElcInfotype elcInfotype, Integer rows, Integer page){
        //分页组件
        /**
         * 当查询时，除了传递参数外，还需要传递分页的参数
         */
        PageHelper.startPage(page,rows);

        if (elcInfotype.getTypeName()!=null) {
            elcInfotype.setTypeName("%"+elcInfotype.getTypeName()+"%");
        }
        //查询所有信息
        List<ElcInfotype> list= elcInfotypeService.queryAll(elcInfotype);
        PageInfo<ElcInfotype> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 处理添加操作
     *
     * F9 -- resume programe 从中断中恢复程序的继续执行
     * F8 -- step over 下一步（跨函数执行，只关心函数的执行结果，不进入函数里面）
     * F7 -- step into 单步执行（进入函数）
     * alt+shift+f7 --- 强制进入函数内
     * shift+f8 --- step out
     * @param elcInfotype
     * @return
     */
    @RequestMapping("add")
    public String addUser(ElcInfotype elcInfotype){
        System.out.println(elcInfotype);
        elcInfotype.setCreateTime(new Date());
        elcInfotype.setUpdateTime(new Date());
        elcInfotypeService.insert(elcInfotype);
        return "success";
    }
    @RequestMapping("query/{id}")
    public ElcInfotype queryUserById(@PathVariable Integer id){
        ElcInfotype elcInfotype = elcInfotypeService.queryById(id);
        return elcInfotype;
    }
    @GetMapping("/update")
    public String updateUser(ElcInfotype elcInfotype){
        elcInfotype.setUpdateTime(new Date());
        elcInfotypeService.update(elcInfotype);
        return "success";
    }
    @RequestMapping("delete/{id}")
    public String delUser(@PathVariable Integer id){
        elcInfotypeService.deleteById(id);
        return "success";
    }

    @RequestMapping("dels/{ids}")
    public String delelcInfotype(@PathVariable Integer[] ids){

        elcInfotypeService.deleteByIds(ids);
        return "success";

    }



    @RequestMapping("queryOne")
    public List<ElcInfotype> queryAll(ElcInfotype elcInfotype){
        List<ElcInfotype> list = elcInfotypeService.queryOne(elcInfotype);
        return list;
    }

    /**
     * 把表导出到excel，
     * @param elcInfotype
     * @return
     */
    @RequestMapping("excel")
    public List<ElcInfotype> excel(ElcInfotype elcInfotype){
        return elcInfotypeService.excel(elcInfotype);
    }


}
